package com.android.dongshouzhi.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.android.dongshouzhi.MainActivity;
import com.android.dongshouzhi.R;
import com.android.dongshouzhi.activity.BaseObject;
import com.android.dongshouzhi.activity.BaseWeb;
import com.android.dongshouzhi.activity.GoodsDetailActivity;
import com.android.dongshouzhi.activity.mine.BuyTicketActivity;
import com.android.dongshouzhi.activity.mine.LoginActivity;
import com.android.dongshouzhi.activity.mine.NewGuideActivity;
import com.android.dongshouzhi.activity.mine.ScoreSignInActivity;
import com.android.dongshouzhi.adapt.GridMainMarketAdapt;
import com.android.dongshouzhi.model.MainTabData;
import com.android.dongshouzhi.model.auction.AuctionActivityData;
import com.android.dongshouzhi.model.auction.AuctionActivitySendData;
import com.android.dongshouzhi.model.auction.AuctionActivitySendData1;
import com.android.dongshouzhi.model.auction.AuctionBannerData;
import com.android.dongshouzhi.model.auction.AuctionRecentlyOrder;
import com.android.dongshouzhi.model.auction.AuctionRecentlyOrderCallback;
import com.android.dongshouzhi.model.auction.AuctionResultData;
import com.android.dongshouzhi.model.auction.Auction_DetailRecentlyData;
import com.android.dongshouzhi.model.auction.Auction_DetailRecentlySendData;
import com.android.dongshouzhi.model.auction.Auction_JoinBackData;
import com.android.dongshouzhi.model.auction.Auction_NavData;
import com.android.dongshouzhi.model.auction.UpdateAuctionBean;
import com.android.dongshouzhi.model.detail.Banner;
import com.android.dongshouzhi.model.detail.MainBannerData;
import com.android.dongshouzhi.model.detail.MainBannerDataCallback;
import com.android.dongshouzhi.model.group.BusinessVoucherListData;
import com.android.dongshouzhi.model.group.BusinessVoucherListDataCallback;
import com.android.dongshouzhi.model.group.DirectBuyGoodsList;
import com.android.dongshouzhi.model.group.DirectBuyGoodsListCallback;
import com.android.dongshouzhi.service.WebSocketService;
import com.android.dongshouzhi.service.WebSocketService3;
import com.android.dongshouzhi.utils.ConstantsUrl;
import com.android.dongshouzhi.utils.HttpUtils;
import com.android.dongshouzhi.utils.LoginState;
import com.android.dongshouzhi.utils.MyLog;
import com.android.dongshouzhi.utils.ObjectUtils;
import com.android.dongshouzhi.view.AutoVerticalScrollTextView;
import com.android.dongshouzhi.view.MyGridView;
import com.android.dongshouzhi.view.group.VRefreshLayout;
import com.android.dongshouzhi.view.group.ViewPagerIndicator;
import com.google.gson.Gson;
import com.mcxtzhang.nestlistview.NestFullListView;
import com.mcxtzhang.nestlistview.NestFullListViewAdapter;
import com.mcxtzhang.nestlistview.NestFullViewHolder;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

import static com.android.dongshouzhi.R.id.no_data;


/**
 * Created by Administrator on 2017/9/29.
 */

public class Fragment11 extends Fragment {
   @BindView(R.id.swipe_refresh_layout)
   VRefreshLayout mRefreshLayout;
    @BindView(R.id.click_resetnetwork_refresh)
    TextView clickResetnetworkRefresh;
    @BindView(R.id.click_resetnetwork)
    LinearLayout clickResetnetwork;
    @BindView(R.id.no_data_tv)
    TextView noDataTv;
    @BindView(no_data)
    RelativeLayout noData;
    @BindView(R.id.progress)
    RelativeLayout progress;
    @BindView(R.id.main_top_title)
    TextView mainTopTitle;
    @BindView(R.id.main_top_bg)
    Toolbar mainTopBg;
    @BindView(R.id.scroll)
    ScrollView scroll;
    @BindView(R.id.custom_ll)
    LinearLayout custom_ll;
    @BindView(R.id.type_ll)
    LinearLayout type_ll;
    @BindView(R.id.bannerpager_fragment)
    ViewPager bannerpager;
    @BindView(R.id.viewPagerIndicator1)
    ViewPagerIndicator viewPagerIndicator1;
    @BindView(R.id.mine_sign_in)
    TextView mine_sign_in;
    @BindView(R.id.main_fragment_grid_sort1)
    NestFullListView main_fragment_grid_sort1;
    @BindView(R.id.main_voucher_grid)
    NestFullListView main_voucher_grid;
    @BindView(R.id.ll_voucher_list)
    LinearLayout ll_voucher_list;
    @BindView(R.id.auction_topline_tv)
    AutoVerticalScrollTextView auction_topline_tv;
    @BindView(R.id.auctioning_v)
    View auctioning_v;
    @BindView(R.id.newerprefecture_v)
    View newerprefecture_v;
    @BindView(R.id.mine_auction_v)
    View mine_auction_v;
    @BindView(R.id.auctioning_lt)
    RelativeLayout auctioning_lt;
    @BindView(R.id.newerprefecture_lt)
    RelativeLayout newerprefecture_lt;
    @BindView(R.id.mine_auction_lt)
    RelativeLayout mine_auction_lt;
    @BindView(R.id.detail_like_grid)
    MyGridView detail_like_grid;
    @BindView(R.id.detail_like_grid1)
    MyGridView gridview;
    private AdaptList adapter;
    private GridMainMarketAdapt adapter_like;
    private ArrayList<MainTabData> griddata1 = new ArrayList<>();
    private List<BusinessVoucherListData.DataBean.ListBean> voucherlist = new ArrayList<>();
    private Auction_DetailRecentlyData recentlyData = new Auction_DetailRecentlyData();
    private ArrayList<Banner.Bannerdata> Bannerlist = new ArrayList<>();
    private WebSocketService service;
    private BroadcastReceiver mBroadcastReceiver;
    private View view;
    private FragmentActivity mcontext;
    private boolean networkConnected;
    private LayoutInflater inflater;

    private GridLayoutManager mLayoutManager = new GridLayoutManager(mcontext, 2);
    private int page = 1;
    private Message message, message2, message3, message4;

    private int lastOffset, lastPosition;
    private int y;
    private int[] location = new int[2];
    private int mid;
    private String token;
    private HashMap<String, ViewHolder> myViewHolderList = new HashMap<>();
    private HashMap<String, Boolean> isStartMap = new HashMap<>();
    private HashMap<String, Boolean> isMostMap = new HashMap<>();
    private HashMap<String, UpdateAuctionBean> updateBean = new HashMap<>();
    private HashMap<String, UpdateAuctionBean> lastperiodBean = new HashMap<>();
    private Auction_NavData navData = new Auction_NavData();
    private AuctionBannerData auctionBannerData;
    private Auction_DetailRecentlySendData recentlySendData = new Auction_DetailRecentlySendData();
    // private String currentid;
    private AuctionActivitySendData auctionActivitySendData = new AuctionActivitySendData();
    private AuctionActivitySendData1 auctionActivitySendData1 = new AuctionActivitySendData1();
    private AuctionActivityData auctionactivitydata;
    private Auction_JoinBackData auction_joinBackData = new Auction_JoinBackData();
    private AuctionResultData auctionResultData = new AuctionResultData();
    private String auction_style = "auctioning";
    private boolean isRunning = false;
    private boolean isStartThread = false;
    private int count_topline = 0;
    private String[] auction_toplines = new String[3];
    private boolean isVisible;
    private Gson gson = new Gson();
    private String gsonstring = "";
    private ArrayList<AuctionActivityData.ListBean> listdata = new ArrayList<>();
    private ArrayList<AuctionActivityData.ListBean> temporaryf1_listdata = new ArrayList<>();
    private String get_banner = "{\"type\":\"get_banner\"}";
    private String get_menus = "{\"type\":\"get_menus\"}";
    private int voucher_size = 3;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        this.inflater = inflater;
        view = inflater.inflate(R.layout.fragment_fragment11, container, false);
        mcontext = getActivity();
        ButterKnife.bind(this, view);
        String appName = getResources().getString(R.string.app_name);
        mainTopTitle.setText(appName);
        mainTopTitle.setTextColor(Color.parseColor("#ffffff"));
        mainTopBg.setBackgroundColor(Color.parseColor("#FF2741"));
        initUI();
        if (!LoginState.getInstance().getid(mcontext).equals("") && LoginState.getInstance().getid(mcontext) != null) {
            mid = Integer.parseInt(LoginState.getInstance().getid(mcontext));
            token = LoginState.getInstance().getUserInfo(mcontext, 2);
        }
        Refreshdata();
        if (!isStartThread) {
            handler1.post(mRunnable);
            isStartThread = true;
        }
        myViewHolderList.clear();
        temporaryf1_listdata.clear();
        broadcastReceive();
        initData();
        //GetDataBanner();
        //GetDataListData(page);
        return view;
    }


    @Override
    public void onResume()
    {
        super.onResume();
        if(!LoginState.getInstance().getid(mcontext).equals("")&&LoginState.getInstance().getid(mcontext)!=null) {
            mid = Integer.parseInt(LoginState.getInstance().getid(mcontext));
            token = LoginState.getInstance().getUserInfo(mcontext,2);
        }

    }

    //    @Override
//    public void onLoadMoreRequested() {
//        page = page + 1;
//        auctionActivitySendData.setType("get_auctions");
//        auctionActivitySendData.setPage(1);
//        auctionActivitySendData.setPer_page(8);
//        switch (auction_style)
//        {
//            case "auctioning":
//                break;
//            case "mine_auctioning":
//                String mid = LoginState.getInstance().getid(mcontext);
//                auctionActivitySendData.setMid(Integer.parseInt(mid));
//                break;
//            case  "for_new":
//                auctionActivitySendData.setFor_new(0);
//                break;
//        }
//        gsonstring = gson.toJson(auctionActivitySendData);
//        service.sendMsg(gsonstring);
//    }
    protected void initData() {
        if (mRefreshLayout != null) {
            mRefreshLayout.setBackgroundColor(Color.TRANSPARENT);
            mRefreshLayout.setAutoRefreshDuration(400);
         //   mRefreshLayout.setRatioOfHeaderHeightToReach(1.5f);
            mRefreshLayout.addOnRefreshListener(new VRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    networkConnected = ObjectUtils.isNetworkConnected(mcontext);
                    if (networkConnected) {
                        mRefreshLayout.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                myViewHolderList.clear();
                                temporaryf1_listdata.clear();
                                if(listdata!=null) {
                                    listdata.clear();
                                }
                                service = WebSocketService.getInstance();
                                service.sendMsg(get_banner);
                                auctioning_v.setVisibility(View.VISIBLE);
                                newerprefecture_v.setVisibility(View.INVISIBLE);
                                mine_auction_v.setVisibility(View.INVISIBLE);
                                auction_style = "auctioning";
                                page=1;
                                mRefreshLayout.refreshComplete();
                                auctionActivitySendData.setType("get_auctions");
                                auctionActivitySendData.setPage(1);
                                auctionActivitySendData.setPer_page(8);
                                switch (auction_style)
                                {
                                    case "auctioning":
                                        auctionActivitySendData.setCid(0);
                                        break;
                                    case "mine_auctioning":
                                        String mid = LoginState.getInstance().getid(mcontext);
                                        auctionActivitySendData.setMid(Integer.parseInt(mid));
                                        break;
                                    case  "for_new":
                                        auctionActivitySendData.setFor_new(0);
                                        break;
                                }
                                gsonstring = gson.toJson(auctionActivitySendData);
                                service.sendMsg(gsonstring);
                                GetVoucher();
                                GetListData();
                                // getMianThematic_Insert();
                            }
                        }, 1000);
                    } else {
                        ObjectUtils.toast(mcontext, "网络连接出现异常");
                    }
                }
            });
        }
        for(int i=0;i<3;i++)
        {
            auction_toplines[i] = "暂无竞买消息";
        }

        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        if (networkConnected) {
            auctionActivitySendData.setType("get_auctions");
            auctionActivitySendData.setPage(1);
            auctionActivitySendData.setPer_page(8);
            switch (auction_style)
            {
                case "auctioning":
                    auctionActivitySendData.setCid(0);
                    break;
                case "mine_auctioning":
                    String mid = LoginState.getInstance().getid(mcontext);
                    auctionActivitySendData.setMid(Integer.parseInt(mid));
                    break;
                case  "for_new":
                    auctionActivitySendData.setFor_new(0);
                    break;
            }
            gsonstring = gson.toJson(auctionActivitySendData);
            service.sendMsg(gsonstring);

        } else {
            ObjectUtils.GetDataNet(clickResetnetwork, progress, 4);
        }
        isRunning = true;

        //   更新拼团快报
        new Thread() {
            @Override
            public void run() {
                while (isRunning) {
                    SystemClock.sleep(3000);
                    handler2.sendEmptyMessage(1);
                }
            }
        }.start();
        GetVoucher();
        GetListData();
    }

    /**
     * 获取优惠券消息
     */
    private void GetVoucher()
    {
        if(voucher_size == 0){
            ll_voucher_list.setVisibility(View.GONE);
            return;
        }else {
            ll_voucher_list.setVisibility(View.VISIBLE);
        }
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address = ConstantsUrl.domain + ConstantsUrl.VOUCHERLIST;
        MyLog.e("地址", address);
        if (networkConnected) {
            HashMap<String, String> map = new HashMap<>();
            map.put("page","1");
            map.put("size","3");
            HttpUtils.post(address,map, new BusinessVoucherListDataCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {
                            ObjectUtils.toast(mcontext,e.getMessage());
                        }

                        @Override
                        public void onResponse(BusinessVoucherListData response, int id) {

                            if (response.getCode() == 0) {
                                if(response.getData().getList()!=null) {
                                    voucherlist.clear();
                                    voucherlist.addAll(response.getData().getList());
                                    if(voucherlist.size() > voucher_size){
                                        voucherlist = voucherlist.subList(0, voucher_size);
                                    }
                                    main_voucher_grid.setAdapter(new NestFullListViewAdapter<BusinessVoucherListData.DataBean.ListBean>(R.layout.item_mainvoucher,voucherlist) {
                                        @Override
                                        public void onBind(int position,BusinessVoucherListData.DataBean.ListBean testBean, NestFullViewHolder holder) {
                                            if(testBean.getEnd_time().equals("0"))
                                            {
                                                holder.setVisible(R.id.foreveruse_ll,true);
                                                holder.setVisible(R.id.usetime_ll,false);
                                            }
                                            else
                                            {
                                                holder.setVisible(R.id.foreveruse_ll,false);
                                                holder.setVisible(R.id.usetime_ll,true);
                                                int s_time = Integer.parseInt(testBean.getStart_time());
                                                long msl = (long) s_time * 1000;
                                                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                                                String text = format.format(msl);
                                                holder.setText(R.id.start_time, text);
                                                // mainlistdata.setStart_time(text);
                                                int e_time = Integer.parseInt(testBean.getEnd_time());
                                                long msl1 = (long) e_time * 1000;
                                                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                                                String text1 = format1.format(msl1);
                                                holder.setText(R.id.end_time, text1);
                                                //  mainlistdata.setEnd_time(text1);
                                            }
                                            holder.setText(R.id.auction_bean, testBean.getCoin());
                                            holder.setText(R.id.voucher_price,testBean.getPrice());
                                            holder.setText(R.id.voucher_title, testBean.getTitle());
                                            holder.setText(R.id.voucher_summary, testBean.getSummary());
                                            ObjectUtils.photo2(mcontext, testBean.getThumb(), ((ImageView) holder.getView(R.id.main_voucher_iv)));

                                        }
                                    });

                                    main_voucher_grid.setOnItemClickListener(new NestFullListView.OnItemClickListener() {
                                        @Override
                                        public void onItemClick(NestFullListView nestFullListView, View view, int pos) {
                                            Intent intent_voucher = new Intent(mcontext,BuyTicketActivity.class);
                                            startActivity(intent_voucher);
                                        }
                                    });
                                }
                                else
                                {

                                }
                            }
                            else
                            {
                                for(int i=0;i<3;i++)
                                {
                                    auction_toplines[i] = "暂无竞买消息";
                                }
                            }
                        }
                    }

            );
        } else {
            ObjectUtils.toast(mcontext, "网络连接出现异常");
        }
    }
    /**
     * 获取直购消息
     */
    private void GetListData() {
        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
        String address = ConstantsUrl.domain + ConstantsUrl.DIRECTBUY_GOODSLISTSDATA;
        HashMap<String, String> map = new HashMap<>();
        map.put("page","1");
        map.put("size","4");
        map.put("id", "0");
        if (networkConnected) {
            HttpUtils.get(address, map, listCallback);
        } else {
            if (page == 1) {
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
            }
            ObjectUtils.toast(getActivity(), "网络连接出现异常，无大市场产品");
        }
    }

    DirectBuyGoodsListCallback listCallback = new DirectBuyGoodsListCallback() {

        @Override
        public void onError(Call call, Exception e, int id) {
            ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
        }

        @Override
        public void onResponse(DirectBuyGoodsList response, int id) {
            ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
            if (response.getCode() == 0) {

                if (response.getList() != null && response.getList().size() > 0) {
                    adapter_like = new GridMainMarketAdapt(mcontext,response.getList());
                    detail_like_grid.setAdapter(adapter_like);

                    // adapter.notifyDataSetChanged();
                }
            } else {
//                noData.setVisibility(View.VISIBLE);
//                noDataTv.setVisibility(View.VISIBLE);
//                noDataTv.setText(response.getMsg());
            }
        }
    };
    private void Refreshdata() {
        GetRecentlyQuery();
    }
    private void initUI() {
        SharedPreferences myPref = mcontext.getSharedPreferences(ConstantsUrl.SHAREDPREFERENCES_NAME, 0);
        String strVouSize = myPref.getString(ConstantsUrl.INDEX_VOUCHER_SIZE, "3");
        voucher_size = Integer.parseInt(strVouSize);
        adapter = new AdaptList(mcontext,listdata);
        gridview.setAdapter(adapter);
        scroll.smoothScrollTo(0, 0);
//        fragment_head = inflater.inflate(R.layout.main_fragment1_head_banner, null, false);
//        type_ll = (LinearLayout)fragment_head.findViewById(R.id.type_ll);
//        bannerpager = (ViewPager) fragment_head.findViewById(R.id.bannerpager_fragment);
//        viewPagerIndicator1 = (ViewPagerIndicator) fragment_head.findViewById(R.id.viewPagerIndicator1);
//        main_fragment_grid_sort1 = (NestFullListView) fragment_head.findViewById(R.id.main_fragment_grid_sort1);
//        main_voucher_grid = (NestFullListView) fragment_head.findViewById(R.id.main_voucher_grid);
//        auction_topline_tv = ( AutoVerticalScrollTextView )fragment_head.findViewById(R.id.auction_topline_tv);
//        auctioning_v = (View) fragment_head.findViewById(R.id.auctioning_v);
//        newerprefecture_v = (View) fragment_head.findViewById(R.id.newerprefecture_v);
//        mine_auction_v = (View) fragment_head.findViewById(R.id.mine_auction_v);
//        auctioning_lt = (RelativeLayout) fragment_head.findViewById(R.id.auctioning_lt);
//        newerprefecture_lt = (RelativeLayout) fragment_head.findViewById(R.id.newerprefecture_lt);
//        mine_auction_lt = (RelativeLayout) fragment_head.findViewById(R.id.mine_auction_lt);
//        foot_head = inflater.inflate(R.layout.main_fragment1_foot_banner, null, false);
//        detail_like_grid = (MyGridView) foot_head.findViewById(R.id.detail_like_grid);
        auctioning_lt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myViewHolderList.clear();
                temporaryf1_listdata.clear();
                if(listdata!=null)
                listdata.clear();
                auctioning_v.setVisibility(View.VISIBLE);
                newerprefecture_v.setVisibility(View.INVISIBLE);
                mine_auction_v.setVisibility(View.INVISIBLE);
                page=1;
                auction_style ="auctioning";
                auctionActivitySendData.setCid(0);
                auctionActivitySendData.setMid(0);
                auctionActivitySendData.setFor_new(0);
                auctionActivitySendData.setType("get_auctions");
                auctionActivitySendData.setPage(1);
                auctionActivitySendData.setPer_page(8);
                switch (auction_style)
                {
                    case "auctioning":
                        auctionActivitySendData.setCid(0);
                        break;
                    case "mine_auctioning":
                        String mid = LoginState.getInstance().getid(mcontext);
                        auctionActivitySendData.setMid(Integer.parseInt(mid));
                        break;
                    case  "for_new":
                        auctionActivitySendData.setFor_new(0);
                        break;
                }
                gsonstring = gson.toJson(auctionActivitySendData);
                service.sendMsg(gsonstring);
            }
        });
        newerprefecture_lt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myViewHolderList.clear();
                temporaryf1_listdata.clear();
                if(listdata!=null)
                listdata.clear();
                auctioning_v.setVisibility(View.INVISIBLE);
                newerprefecture_v.setVisibility(View.VISIBLE);
                mine_auction_v.setVisibility(View.INVISIBLE);
                page=1;
                auction_style ="for_new";
                auctionActivitySendData1.setType("get_auctions");
                auctionActivitySendData1.setPage(1);
                auctionActivitySendData1.setPer_page(8);
                auctionActivitySendData1.setFor_new(1);
                gsonstring = null;
                gsonstring = gson.toJson(auctionActivitySendData1);
                service.sendMsg(gsonstring);

            }
        });
        mine_auction_lt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (LoginState.getInstance().isLogin(mcontext)) {
                    myViewHolderList.clear();
                    temporaryf1_listdata.clear();
                    listdata.clear();
                    auctioning_v.setVisibility(View.INVISIBLE);
                    newerprefecture_v.setVisibility(View.INVISIBLE);
                    mine_auction_v.setVisibility(View.VISIBLE);
                    page=1;
                    auction_style ="mine_auctioning";
                    auctionActivitySendData.setCid(0);
                    auctionActivitySendData.setMid(0);
                    auctionActivitySendData.setFor_new(0);
                    auctionActivitySendData.setType("get_auctions");
                    auctionActivitySendData.setPage(1);
                    auctionActivitySendData.setPer_page(8);
                    switch (auction_style)
                    {
                        case "auctioning":
                            auctionActivitySendData.setCid(0);
                            break;
                        case "mine_auctioning":
                            String mid = LoginState.getInstance().getid(mcontext);
                            if(mid!=null&&!mid.equals("")) {
                                auctionActivitySendData.setMid(Integer.parseInt(mid));
                            }
                            break;
                        case  "for_new":
                            auctionActivitySendData.setFor_new(0);
                            break;
                    }
                    gsonstring = gson.toJson(auctionActivitySendData);
                    service.sendMsg(gsonstring);
                }
                else
                {
                    startActivityForResult(new Intent(mcontext, LoginActivity.class),2);
                }
            }
        });
        detail_like_grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //currentid = temporaryf1_listdata.get(position).getId();
                if (LoginState.getInstance().isLogin(mcontext)) {
                Intent intent = new Intent(mcontext, GoodsDetailActivity.class);
                intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_DETAIL_SHOW, 1);
                intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_DETAIL_ID,listdata.get(position).getId());
                intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_DETAIL_COMMON_ID,"");
                startActivityForResult(intent,1);
                }
                else
                {
                    startActivityForResult(new Intent(mcontext, LoginActivity.class),2);
                }
            }
        });
    }

    /**
     * 分类跳转
     */

    class MainSortStartTo implements NestFullListView.OnItemClickListener {
        ArrayList<MainTabData> griddata;

        public MainSortStartTo(ArrayList<MainTabData> griddata) {
            this.griddata = griddata;
        }

        @Override
        public void onItemClick(NestFullListView nestFullListView, View view, int position) {
            MainTabData mainTabData = griddata.get(position);
            String href = mainTabData.getHref();
            switch (href) {
                case "tab.auction":
                    MainActivity B = (MainActivity) getActivity();
                    B.ChangeMainFragment(2);
                    break;
                case "voucher":
                    Intent intent_voucher = new Intent(mcontext,BuyTicketActivity.class);
                    startActivity(intent_voucher);
                    break;
                case "guide":
                    Intent intent_q = new Intent(getActivity(), NewGuideActivity.class);
                    intent_q.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL,ConstantsUrl.baseDomain + "home/www/#/guide");
                    intent_q.putExtra("title",mainTabData.getName());
                    startActivity(intent_q);
                    break;
                case "goods":
                    Intent intent_address = new Intent(mcontext, BaseObject.class);
                    intent_address.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, "大市场");
                    startActivity(intent_address);
                    break;
                case "service":
                    Intent intent_address1 = new Intent(mcontext, BaseObject.class);
                    intent_address1.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, "客服中心");
                    startActivity(intent_address1);
                    break;
                case "sign":
                    if (LoginState.getInstance().isLogin(mcontext)) {
                        startActivity(new Intent(getActivity(), ScoreSignInActivity.class));
                    } else {
                        startActivity(new Intent(mcontext, LoginActivity.class));
                    }
                    break;
                default:
                    if(href.startsWith("http")){
                        toWeb(href);
                    }
                    break;
            }
        }
    }

    private void toWeb(String href) {
        Intent intent = new Intent(getActivity(), BaseWeb.class);
        intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_MEMBER_WEB_URL, href);
        startActivity(intent);
    }

    /**
     * 轮播图销毁开启
     */

    @Override
    public void onStart() {
        super.onStart();

        viewPagerIndicator1.setVisible(true);
    }


    @Override
    public void onPause() {
        super.onPause();

        viewPagerIndicator1.setVisible(false);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode)
        {
            case 1:
                if(data!=null) {
                    // 获取传递的数据
                    Bundle bundle = data.getExtras();
                    // 获得返回值
                    String id = bundle.getString("auction_id");
                    String period = bundle.getString("auction_period");
                    recentlySendData.setType("join_log");
                    String order_sn = id + "_" + period;
                    recentlySendData.setOrder_sn(order_sn);
                    recentlySendData.setPage(1);
                    recentlySendData.setPer_page(2);
                    gsonstring = gson.toJson(recentlySendData);
                    service.sendMsg(gsonstring);
                }
                break;
            case 2:
                myViewHolderList.clear();
                temporaryf1_listdata.clear();
                if(listdata!=null)
                listdata.clear();
                auctioning_v.setVisibility(View.VISIBLE);
                newerprefecture_v.setVisibility(View.INVISIBLE);
                mine_auction_v.setVisibility(View.INVISIBLE);
                page=1;
                auction_style ="auctioning";
                auctionActivitySendData.setType("get_auctions");
                auctionActivitySendData.setPage(1);
                auctionActivitySendData.setPer_page(8);
                switch (auction_style)
                {
                    case "auctioning":
                        break;
                    case "mine_auctioning":
                        String mid = LoginState.getInstance().getid(mcontext);
                        if(mid!=null&&!mid.equals("")) {
                            auctionActivitySendData.setMid(Integer.parseInt(mid));
                        }
                        break;
                    case  "for_new":
                        auctionActivitySendData.setFor_new(0);
                        break;
                }
                gsonstring = gson.toJson(auctionActivitySendData);
                service.sendMsg(gsonstring);
                break;
        }
    }

    @OnClick({R.id.mine_sign_in,R.id.click_resetnetwork_refresh,R.id.topline_ll,R.id.big_market})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.topline_ll:
                Intent intent_topline_ll = new Intent(mcontext, BaseObject.class);
                intent_topline_ll.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"最新成交");
                startActivity(intent_topline_ll);
                break;
            case R.id.mine_sign_in:
                Intent intent_voucher = new Intent(mcontext,BuyTicketActivity.class);
                startActivity(intent_voucher);
                break;
            case R.id.big_market:
                Intent intent = new Intent(mcontext, BaseObject.class);
                intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"大市场");
                startActivity(intent);
                break;
            case R.id.click_resetnetwork_refresh:
                myViewHolderList.clear();
                temporaryf1_listdata.clear();
                service.sendMsg(get_banner);
                page = 1;
                auctionActivitySendData.setType("get_auctions");
                auctionActivitySendData.setPage(1);
                auctionActivitySendData.setPer_page(8);
                switch (auction_style)
                {
                    case "auctioning":
                        break;
                    case "mine_auctioning":
                        String mid = LoginState.getInstance().getid(mcontext);
                        auctionActivitySendData.setMid(Integer.parseInt(mid));
                        break;
                    case  "for_new":
                        auctionActivitySendData.setFor_new(0);
                        break;
                }
                gsonstring = gson.toJson(auctionActivitySendData);
                service.sendMsg(gsonstring);
                break;

        }
    }
    //设置广播监听
    private void broadcastReceive()
    {
        service = WebSocketService.getInstance();
        GetBanner();
        GetMenus();
        //service.sendMsg(get_menus);
        mBroadcastReceiver = new BroadcastReceiver(){
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                //更新竞买返回消息
                if(action.equals(WebSocketService.ACTION_NOT)){
                    Intent intents = mcontext.getIntent();
                    auctionResultData = (AuctionResultData)intent.getBundleExtra("bundle").getSerializable("AuctionResult");
                    if(auctionResultData!=null)
                    {
                        if(!auction_style.equals("mine_auctioning"))
                        {
                            DealWithResult();
                        }
                    }
                }
                if(action.equals(WebSocketService.ACTION_Nav))
                {
                    navData = ( Auction_NavData)intent.getBundleExtra("bundle6").getSerializable("AuctionNav");
                    griddata1.clear();
                    for(int i=0;i<navData.getList().size();i++)
                    {
                        griddata1.add(new MainTabData(navData.getList().get(i).getTitle(),(i+1)+"",navData.getList().get(i).getSrc()));
                    }
                    //分类+快报
                    main_fragment_grid_sort1.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata1) {
                        @Override
                        public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                            holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                            ObjectUtils.photo2(mcontext,testBean.getSrc(),(ImageView)holder.getView(R.id.item_grid_fragment_sort_img));
                        }
                    });
                    main_fragment_grid_sort1.setOnItemClickListener(new MainSortStartTo(griddata1));
                }
                if(action.equals(WebSocketService.ACTION_BANNER))
                {
                    auctionBannerData = (AuctionBannerData)intent.getBundleExtra("bundle1").getSerializable("AuctionBanner");
                }
                //更新商品列表
                if(action.equals(WebSocketService.ACTION_AUCTION))
                {
                    boolean isUpdateUsername =false;
                    auctionactivitydata = (AuctionActivityData) intent.getBundleExtra("bundle2").getSerializable("AuctionGetAuctions");
                    if(auctionactivitydata.getList()!=null&&auctionactivitydata.getList().size()>0) {
                        int midd=0;
//                        if(auctionactivitydata.getList().get(0).getMid()!=null)
//                        {
//                            midd = Integer.parseInt(auctionactivitydata.getList().get(0).getMid());
//                        }
//                        if(midd>0)
//                        {
//                            isUpdateUsername =true;
//                        }
                        listdata = new ArrayList<>();
                        if(page==1)
                        {
                            temporaryf1_listdata.clear();
                        }
                        for (int i = 0; i < auctionactivitydata.getList().size(); i++) {
//                            if(isUpdateUsername)
//                            {
////                                   if (auctionactivitydata.getList().get(i).getUsername() != null && !auctionactivitydata.getList().get(i).getUsername().equals(""))
////                                   {
////                                       currentlyUser.put(auctionactivitydata.getList().get(i).getId(), auctionactivitydata.getList().get(i).getUsername());
////                                   }
//                            }
//                            else {

                            AuctionActivityData.ListBean listBean = auctionactivitydata.getList().get(i);
                            long currentTimeMillis = System.currentTimeMillis()/1000 - 2;
                            int time = listBean.getTime();
                            int start = listBean.getStart();
                            long endTime = currentTimeMillis + time;
                            long startTime = currentTimeMillis + start;
                            String price = listBean.getPrice();
                            price = ObjectUtils.decimalFormat(price);
                            temporaryf1_listdata.add(new AuctionActivityData.ListBean(AuctionActivityData.ListBean.THREE, listBean.getId()
                                    , listBean.getPeriod(), listBean.getTitle()
                                    , listBean.getThumb(), price
                                    , time, start
                                    , listBean.getMid(), listBean.getUsername(),startTime,endTime));
                            listdata.add(new AuctionActivityData.ListBean(AuctionActivityData.ListBean.THREE, listBean.getId()
                                    , listBean.getPeriod(), listBean.getTitle()
                                    , listBean.getThumb(), price
                                    , time, start
                                    , listBean.getMid(), listBean.getUsername(),startTime,endTime));
                            if (start != 0)
                            {
                                isStartMap.put(listBean.getId(), true);
                            }
                            else {
                                isStartMap.put(listBean.getId(), false);
                            }
                            if(listBean.getMid()!=null&&!listBean.getMid().equals(""))
                            {
                                if(listBean.getMid().equals(mid+"")) {
                                    isMostMap.put(listBean.getId(), true);
                                }
                                else
                                {
                                    isMostMap.put(listBean.getId(),false);
                                }
                            }
                            else
                            {
                                isMostMap.put(listBean.getId(), false);
                            }
                            updateBean.put(listBean.getId(),new UpdateAuctionBean());
                            lastperiodBean.put(listBean.getId(),new UpdateAuctionBean());
                            // }
                        }
//                        if(isUpdateUsername)
//                        {
//                            //  handler1.post(mRunnable3);
//                        }
//                        else
//                        {

                        AdapterListData();
                        //}
                    }
                    else
                    {
                        gridview.setVisibility(View.GONE);
                        noData.setVisibility(View.VISIBLE);
                    }

                }
                //趣买最新出价（判断自己当前出价是否为最高）
                if (action.equals(WebSocketService3.ACTION_JOINLOG)) {
                    recentlyData = (Auction_DetailRecentlyData) intent.getBundleExtra("bundle5").getSerializable("AuctionJoinLog");

                    if(recentlyData.getList()!=null&&recentlyData.getList().size()>0) {
                        if(recentlyData.getList().get(0).getMid().equals(mid+"")) {
                            Message message = new Message();
                            message.what = 5;
                            handler1.sendMessage(message);
                        }
                    }
                }
                //更新商品趣买时间，价格，出价人
                if(action.equals(WebSocketService.ACTION_JOINBACK))
                {
                    auction_joinBackData = (Auction_JoinBackData)intent.getBundleExtra("bundle3").getSerializable("AuctionJoinBack");
                    String code = auction_joinBackData.getCode();
                    if(code!=null&&!code.equals(""))
                    {
                        if(Integer.parseInt(code)>0)
                        {
                            ObjectUtils.toast(mcontext,auction_joinBackData.getMsg());
                        }
                    }

                    if(temporaryf1_listdata!=null) {
                        long currentTimeMillis = System.currentTimeMillis()/1000 - 1;
                        boolean isupdateusername = false;
                        for (int i = 0; i < temporaryf1_listdata.size(); i++) {
                            AuctionActivityData.ListBean listBean = temporaryf1_listdata.get(i);
                            int id = Integer.parseInt(listBean.getId());
                            if (auction_joinBackData.getId() == id) {
                                if(!auction_joinBackData.getUsername().equals("")&&auction_joinBackData.getPrice()>0)
                                {
                                    isupdateusername = true;
                                    isMostMap.put(listBean.getId(),false);
                                    UpdateAuctionBean update = new UpdateAuctionBean();
                                    update.setUsername(auction_joinBackData.getUsername());
                                    update.setPrice(auction_joinBackData.getPrice());
                                    updateBean.put(listBean.getId(),update);
                                    int time = auction_joinBackData.getTime();
                                    if(time >0)
                                    {
                                        listBean.setTime(time);
                                        long endTime = currentTimeMillis + time;
                                        listBean.setEndTime(endTime);
                                    }
                                    if(auction_joinBackData.getMid()>0)
                                    {
                                        listBean.setMid(auction_joinBackData.getMid()+"");
                                    }
                                    break;
                                }
                            }
                        }
                        if(isupdateusername)
                        {
                            handler1.post(mRunnable3);
                        }
                    }
                }
//                   if(action.equals(WebSocketService.ACTION_Nav))
//                   {
//                       navData= (Auction_NavData) intent.getBundleExtra("bundle2").getSerializable("AuctionNav");
//                       GetMenus();
//                   }

            }
        };
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(WebSocketService3.ACTION_JOINLOG);
        myIntentFilter.addAction(WebSocketService.ACTION_NOT);
        myIntentFilter.addAction(WebSocketService.ACTION_BANNER);
        myIntentFilter.addAction(WebSocketService.ACTION_AUCTION);
        myIntentFilter.addAction(WebSocketService.ACTION_JOINBACK);
        myIntentFilter.addAction(WebSocketService.ACTION_Nav);
        //注册广播
        mcontext.registerReceiver(mBroadcastReceiver, myIntentFilter);


    }
    /**
     * 获取最新成交消息
     */
    private void GetRecentlyQuery()
    {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address =  ConstantsUrl.domain+ConstantsUrl.ACUTIONRECENTLYORDER;
        MyLog.e("地址", address);
        if (networkConnected) {
            HashMap<String, String> map = new HashMap<>();
            map.put("page","1");
            map.put("size","3");
            HttpUtils.post(address,map, new AuctionRecentlyOrderCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {
                            ObjectUtils.toast(mcontext,e.getMessage());
                        }

                        @Override
                        public void onResponse(AuctionRecentlyOrder response, int id) {

                            if (response.getCode() == 0) {
                                if(response.getData().getList()!=null) {
                                    int size =3;
                                    if(response.getData().getList().size()<3)
                                    {
                                        size = response.getData().getList().size();
                                    }

                                    String keyName = getString(R.string.app_keyname);
                                    for (int i = 0; i < size; i++) {
                                        String content = "恭喜" +response.getData().getList().get(i).getUsername()+"以"
                                                +"<font color='#FF0000'>"+"¥"+response.getData().getList().get(i).getPrice()+"</font>"+ keyName + "到"
                                                +"<font color='#99ccff'>"+response.getData().getList().get(i).getTitle()+"</font>";
                                        auction_toplines[i] = content;
                                    }

                                    if(auction_topline_tv != null){
                                        auction_topline_tv.setText(Html.fromHtml(auction_toplines[0]));
                                    }
                                }
                                else
                                {
                                    for(int i=0;i<3;i++)
                                    {
                                        auction_toplines[i] = "暂无竞买消息";
                                    }
                                }
                            }
                            else
                            {
                                for(int i=0;i<3;i++)
                                {
                                    auction_toplines[i] = "暂无竞买消息";
                                }
                            }
                        }
                    }

            );
        } else {
            ObjectUtils.toast(mcontext, "网络连接出现异常");
        }
    }
    /**
     * 获取菜单
     */
//    private void GetMenus()
//    {
//        griddata1.clear();
//        if(navData.getList()!=null) {
//            griddata1.add(new MainTabData(navData.getList().get(0).getTitle(), "1",navData.getList().get(0).getSrc()));
//            griddata1.add(new MainTabData(navData.getList().get(0).getTitle(), "2",navData.getList().get(0).getSrc()));
//            griddata1.add(new MainTabData(navData.getList().get(0).getTitle(), "3",navData.getList().get(0).getSrc()));
//            griddata1.add(new MainTabData(navData.getList().get(0).getTitle(), "4",navData.getList().get(0).getSrc()));
//            //分类+快报
//            main_fragment_grid_sort1.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata1) {
//                @Override
//                public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
//                    holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
//                    ImageView v = holder.getView(R.id.item_grid_fragment_sort_img);
//                    ObjectUtils.photo2(mcontext,testBean.getSrc(),v);
//                }
//            });
//            main_fragment_grid_sort1.setOnItemClickListener(new MainSortStartTo(griddata1));
//        }
//    }
    /**
     * 获取轮播图
     */
    private void GetBanner()
    {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address =  ConstantsUrl.domain+ConstantsUrl.FRAGMENT1_BANNER;
        MyLog.e("地址", address);
        if (networkConnected) {
            HttpUtils.post(address,null, new MainBannerDataCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {
                            ObjectUtils.toast(mcontext,e.getMessage());
                        }

                        @Override
                        public void onResponse(MainBannerData response, int id) {

                            if (response.getCode() == 0) {
                                List<MainBannerData.DataBean> dataBeanList = response.getData();
                                if(dataBeanList !=null) {
                                    int size = dataBeanList.size();
                                    if(size >0) {
                                        Bannerlist.clear();
                                        ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                                        for (int i = 0; i < size; i++) {
                                            Banner.Bannerdata data = new Banner.Bannerdata();
                                            MainBannerData.DataBean dataBean = dataBeanList.get(i);
                                            data.setThumb(dataBean.getPath());
                                            data.setLink(dataBean.getLink());
                                            data.setPath("");
                                            Bannerlist.add(data);
                                        }
                                        //轮播图
                                        if(Bannerlist!=null) {
                                            viewPagerIndicator1.autoScroll(getChildFragmentManager(), bannerpager, 1);
                                            viewPagerIndicator1.setViewPager(Bannerlist);
                                            viewPagerIndicator1.setNotifyDataSetChanged();
                                        }
                                    }
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }

            );
        } else {
            ObjectUtils.toast(mcontext, "网络连接出现异常");
        }

    }
    /**
     * 获取轮播图
     */
    private void GetMenus()
    {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address =  ConstantsUrl.domain+ConstantsUrl.FRAGMENT1_MENUS;
        MyLog.e("地址", address);
        if (networkConnected) {
            HttpUtils.post(address,null, new MainBannerDataCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {
                            ObjectUtils.toast(mcontext,e.getMessage());
                        }

                        @Override
                        public void onResponse(MainBannerData response, int id) {

                            if (response.getCode() == 0) {
                                if(response.getData()!=null && response.getData().size()>0) {
                                    griddata1.clear();
                                    for(int i=0;i<response.getData().size();i++)
                                    {
                                        MainBannerData.DataBean dataBean = response.getData().get(i);
                                        griddata1.add(new MainTabData(dataBean.getTitle(),(i+1)+"", dataBean.getSrc(), dataBean.getHref()));
                                    }
                                    //分类+快报
                                    main_fragment_grid_sort1.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata1) {
                                        @Override
                                        public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                                            holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                                            ObjectUtils.photo2(mcontext,testBean.getSrc(),(ImageView)holder.getView(R.id.item_grid_fragment_sort_img));
                                        }
                                    });
                                    main_fragment_grid_sort1.setOnItemClickListener(new MainSortStartTo(griddata1));
                                }
                                else
                                {
                                }
                            }
                            else
                            {
                            }
                        }
                    }

            );
        } else {
            ObjectUtils.toast(mcontext, "网络连接出现异常");
        }

    }
    /**
     * 处理竞买返回通知消息
     */
    private void DealWithResult()
    {
        /**
         * 趣买返回通知重开
         */
        if(auctionResultData.getTime()>0&&auctionResultData.getStart()>0)
        {
            /**
             * 更新重开的商品时间
             */
            if (temporaryf1_listdata != null) {
                long currentTimeMillis = System.currentTimeMillis()/1000 - 1;
                for (int i = 0; i < temporaryf1_listdata.size(); i++) {
                    AuctionActivityData.ListBean listBean = temporaryf1_listdata.get(i);
                    String id = listBean.getId();
                    if (auctionResultData.getId().equals(id)) {
                        int time = auctionResultData.getTime();
                        listBean.setTime(time);
                        int start = auctionResultData.getStart();
                        listBean.setStart(start);
                        long endTime = currentTimeMillis + time;
                        long startTime = currentTimeMillis + start;
                        listBean.setEndTime(endTime);
                        listBean.setStartTime(startTime);
                        if(start >0) {
                            isStartMap.put(listBean.getId(), true);
                        }
                        isMostMap.put(listBean.getId(), false);
                        break;
                    }
                }
            }
            /**
             * 有人中拍时
             */
            if(auctionResultData.getMid()>0)
            {
                /**
                 * 头条
                 */
                String keyName = getString(R.string.app_keyname);
                String content = "恭喜" +auctionResultData.getUsername()+"以"
                        +"<font color='#FF0000'>"+"¥"+auctionResultData.getLast_price()+"</font>"+ keyName + "到"
                        +"<font color='#99ccff'>"+auctionResultData.getTitle()+"</font>";
                for(int i =0;i<2;i++)
                {
                    auction_toplines[i] = auction_toplines[i+1];
                }
                auction_toplines[2] = content;
                /**
                 * 更新上期中拍商品活动状态和数据
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setUsername(auctionResultData.getUsername());
                update.setIspass_in(false);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
            /**
             * 无人中拍时
             */
            else
            {
                /**
                 * 更新上期流拍商品活动状态
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setIspass_in(true);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
        }
        /**
         * 竞买返回通知不重开
         */
        else
        {
            /**
             *
             */
//           if(auction_style.equals("mine_auctioning")) {
//               if (listdata != null) {
//                   for (int i = 0; i < listdata.size(); i++) {
//                       int id = Integer.parseInt(listdata.get(i).getId());
//                       if (auctionResultData.getId() == id) {
//                           listdata.remove(i);
//                           break;
//                       }
//                   }
//               }
//               if (myViewHolderList.containsKey(auctionResultData.getId())) {
//                   myViewHolderList.remove(auctionResultData.getId());
//               }
//           }
            /**
             * 有人中拍时
             */
            if(auctionResultData.getMid()>0)
            {
                /**
                 * 头条
                 */
                String keyName = getString(R.string.app_keyname);
                String content = "恭喜" +auctionResultData.getUsername()+"以"
                        +"<font color='#FF0000'>"+"¥"+auctionResultData.getLast_price()+"</font>"+ keyName + "到"
                        +"<font color='#99ccff'>"+auctionResultData.getTitle()+"</font>";
                for(int i =0;i<2;i++)
                {
                    auction_toplines[i] = auction_toplines[i+1];
                }
                auction_toplines[2] = content;
                /**
                 * 更新上期中拍商品活动状态和数据
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setUsername(auctionResultData.getUsername());
                update.setIspass_in(false);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
            /**
             * 无人中拍时
             */
            else
            {
                /**
                 * 更新上期流拍商品活动状态
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setIspass_in(true);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
        }
    }

    /**
     * 适配商品列表
     */
    private void AdapterListData()
    {
        gridview.setVisibility(View.VISIBLE);
        noData.setVisibility(View.INVISIBLE);
        ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
        //if (page == 1) {
        // adapter.loadMoreEnd();
        //} else {
        //      adapter.addData(listdata);
        //adapter.loadMoreComplete();
        //}

        adapter = new AdaptList(mcontext,listdata);
        gridview.setAdapter(adapter);

        adapter.notifyDataSetChanged();
//        if (auctionactivitydata.getList().size() == 8 ) {
//            adapter.loadMoreComplete();
//        }

    }

    private Handler handler1 = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
                case 1:
                    adapter.notifyTimeData();
                    break;
                case 2:
                    adapter.notifyDataSetChanged();
                    break;
                case 3:
                    adapter.notifyUsernameData();
                    break;
                case 4:
                    adapter.notifyLastPeriod();
                    break;
                case 5:
                    adapter.notifyMostPrice();
                    break;
            }
        }
    };
    //更新快报
    private Handler handler2 = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
                case 1:
                    if(auction_topline_tv != null){
                        auction_topline_tv.next();
                        count_topline++;
                        auction_topline_tv.setText(Html.fromHtml(auction_toplines[count_topline%3]));
                    }
                    break;

            }
        }
    };

    //更新上一期活动是否流拍
    private Runnable mRunnable4 = new Runnable() {
        @Override
        public void run() {
            if (null == message4) {
                message4 = new Message();
            } else {
                message4 = Message.obtain();
            }
            message4.what = 4;
            //发送信息给handler
            handler1.sendMessage(message4);
        }
    };
    //更新当前出价和竞拍人
    private Runnable mRunnable3 = new Runnable() {
        @Override
        public void run() {
            if (null == message3) {
                message3 = new Message();
            } else {
                message3 = Message.obtain();
            }
            message3.what = 3;
            //发送信息给handler
            handler1.sendMessage(message3);
        }
    };
    //更新商品是否过期
    private Runnable mRunnable2 = new Runnable() {
        @Override
        public void run() {
            if (null == message2) {
                message2 = new Message();
            } else {
                message2 = Message.obtain();
            }
            message2.what = 2;
            //发送信息给handler
            handler1.sendMessage(message2);
        }
    };
    //更新商品时间
    private Runnable mRunnable = new Runnable(){

        @Override
        public void run() {
            if( temporaryf1_listdata!=null) {
                long currentTimeMillis = System.currentTimeMillis()/1000;
                for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
                    int start;
                    int time;
                    AuctionActivityData.ListBean listBean = temporaryf1_listdata.get(i);
                    long intervalStart = listBean.getStartTime() - currentTimeMillis;
                    if (intervalStart > 0) {
                        start = (int) intervalStart;
                    }else {
                        start = 0;
                    }
                    listBean.setStart(start);
                    long intervalEnd = listBean.getEndTime() - currentTimeMillis;
                    if (intervalEnd > 0) {
                        time = (int) intervalEnd;
                    }else {
                        time = 0;
                    }
                    listBean.setTime(time);
//                    int time =  temporaryf1_listdata.get(i).getTime();
//                    int start =  temporaryf1_listdata.get(i).getStart();
//
//                    if (start > 0) {
//                        start = start - 1;
//                        temporaryf1_listdata.get(i).setStart(start);
//                    }
//                    if (time > 0) {
//                        time = time - 1;
//                        temporaryf1_listdata.get(i).setTime(time);
//                    }
                }
            }
            if (null == message) {
                message = new Message();
            } else {
                message = Message.obtain();
            }
            message.what = 1;
            //发送信息给handler
            handler1.sendMessage(message);
            //每1000豪秒重启一下线程
            handler1.postDelayed(mRunnable, 1000);
        }
    };


    public class AdaptList extends BaseAdapter {
        private LayoutInflater Inflater;
        private Context content;
        private List<AuctionActivityData.ListBean> listdata;

        public AdaptList(Context content, List<AuctionActivityData.ListBean> listdata) {
            this.listdata = listdata;
            this.content = content;
            this.Inflater = LayoutInflater.from(content);
        }
        @Override
        public int getCount() {
            return listdata==null? 0:listdata.size();
        }
        @Override
        public Object getItem(int position) {
            return null;
        }
        @Override
        public long getItemId(int position) {
            return 0;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder = null;
            holder = new ViewHolder();
            if (convertView == null) {
                convertView = Inflater.inflate(R.layout.item_grid_aishangmainpage, null);
                holder.time_position = position;
                holder.kill_minute = (TextView) convertView.findViewById(R.id.kill_minute);
                holder.kill_second = (TextView) convertView.findViewById(R.id.kill_second);
                holder.kill_millsecond = (TextView) convertView.findViewById(R.id.kill_millsecond);
                holder.item_rightnow_price = (TextView) convertView.findViewById(R.id.item_rightnow_price);
                holder.rightnow_openteam = (TextView) convertView.findViewById(R.id.rightnow_openteam);
                holder.item_lastperiod_person = (TextView) convertView.findViewById(R.id.item_lastperiod_person);
                holder.item_lastperiod_person= (TextView) convertView.findViewById(R.id.item_lastperiod_person);
                holder.item_grid_detail_like_title = ( TextView) convertView.findViewById(R.id.item_grid_detail_like_title);
                holder.item_lastperiod_failed = ( LinearLayout) convertView.findViewById(R.id.item_lastperiod_failed);
                holder.item_lastperiod_ll = ( LinearLayout) convertView.findViewById(R.id.item_lastperiod_ll);
                holder.item_rightnow_ll = ( LinearLayout) convertView.findViewById(R.id.item_rightnow_ll);
                holder.item_rightnow_default = (TextView)convertView.findViewById(R.id.item_rightnow_default);
                holder.item_grid_aishang_img = (ImageView) convertView.findViewById(R.id.item_grid_aishang_img);
                holder.ll_count_down2 = (LinearLayout)convertView.findViewById(R.id.ll_count_down2);
                holder.ll_count_down1 = (LinearLayout)convertView.findViewById(R.id.ll_count_down1);
                holder.cd_day = (TextView) convertView.findViewById(R.id.cd_day);
                holder.cd_hour = (TextView) convertView.findViewById(R.id.cd_hour);
                holder.cd_minute = (TextView) convertView.findViewById(R.id.cd_minute);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            final AuctionActivityData.ListBean mainlistdata = listdata.get(position);
            if(!(myViewHolderList.containsKey(mainlistdata.getId()))) {
                myViewHolderList.put(mainlistdata.getId(),holder);
            }
//            int time1 = mainlistdata.getTime();
//            setCountDown(holder, time1);
            ObjectUtils.photo2(content, mainlistdata.getThumb(), ((ImageView) holder.item_grid_aishang_img));
            holder.item_rightnow_price.setText("当前价: ￥" + mainlistdata.getPrice());
            holder.item_grid_detail_like_title.setText(mainlistdata.getTitle());
//            if(temporaryf1_listdata!=null)
//            {
//                for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
//                    int time = temporaryf1_listdata.get(i).getTime();
//                    int start = temporaryf1_listdata.get(i).getStart();
//                    if (myViewHolderList.containsKey(temporaryf1_listdata.get(i).getId())) {
//                        boolean isstart = isStartMap.get(temporaryf1_listdata.get(i).getId());
//                        boolean isMost = isMostMap.get(temporaryf1_listdata.get(i).getId());
//                        //有start时间时
//                        if (isstart) {
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setText("即将开始");
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setEnabled(false);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setBackgroundResource(R.drawable.corner_yellow_bg2);
//                            String minute = String.format("%02d", start / 3600);
//                            String second = String.format("%02d", start % 3600 / 60);
//                            String millsecond = String.format("%02d", start % 60);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_millsecond.setText(millsecond);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_minute.setText(minute);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_second.setText(second);
//                            if (start == 0) {
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setText("立即拼购");
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).item_rightnow_default.setVisibility(View.VISIBLE);
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).item_lastperiod_failed.setVisibility(View.GONE);
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).item_lastperiod_ll.setVisibility(View.GONE);
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setEnabled(true);
//                                isStartMap.put(temporaryf1_listdata.get(i).getId(), false);
//                            }
//                        }
//                        //没有start时间时
//                        else {
//                            String minute = String.format("%02d", time / 3600);
//                            String second = String.format("%02d", time % 3600 / 60);
//                            String millsecond = String.format("%02d", time % 60);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_millsecond.setText(millsecond);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_minute.setText(minute);
//                            myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_second.setText(second);
//                            if (time > 0) {
//                                if (!isMost) {
//                                    myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setText("立即拼购");
//                                    myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
//                                    myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setEnabled(true);
//
//                                } else {
//                                    myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setText("你已最高");
//                                    myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
//                                    myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setEnabled(false);
//                                }
//                            }
//                            if (time == 0) {
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_millsecond.setText("00");
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_minute.setText("00");
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).kill_second.setText("00");
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setText("出价结束");
//                                myViewHolderList.get(temporaryf1_listdata.get(i).getId()).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
//                            }
//
//                        }
//                    }

                //}}

            return convertView;

        }

        //更新当前出价竞拍人
        public void notifyUsernameData() {
            if( temporaryf1_listdata!=null) {

                for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
                    String id =  temporaryf1_listdata.get(i).getId();
                    if (myViewHolderList.containsKey(id)) {
                        if(updateBean.get(id).getPrice()>0) {
                            isMostMap.put(id,false);
                            myViewHolderList.get(id).item_lastperiod_failed.setVisibility(View.GONE);
                            myViewHolderList.get(id).item_rightnow_default.setVisibility(View.GONE);
                            myViewHolderList.get(id).item_lastperiod_ll.setVisibility(View.VISIBLE);
                            myViewHolderList.get(id).item_lastperiod_person.setText("ID: "+updateBean.get(id).getUsername());
                            myViewHolderList.get(id).item_rightnow_price.setText("当前价: ￥" + updateBean.get(id).getPrice());
                            myViewHolderList.get(id).rightnow_openteam.setText(R.string.app_fragment3_keyname);
                            myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
                            myViewHolderList.get(id).rightnow_openteam.setEnabled(true);
                        }
                    }
                }
            }
        }
        //更新商品活动最高价
        public void notifyMostPrice() {
            if(temporaryf1_listdata!=null) {
                for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
                    Auction_DetailRecentlyData data = recentlyData;
                    String id = temporaryf1_listdata.get(i).getId();
                    if (myViewHolderList.containsKey(id)&&temporaryf1_listdata.get(i).getMid()!=null&&!temporaryf1_listdata.get(i).getMid().equals("")) {

                        if(temporaryf1_listdata.get(i).getMid().equals(data.getList().get(0).getMid())) {
                            isMostMap.put(id, true);
                            myViewHolderList.get(id).item_lastperiod_failed.setVisibility(View.GONE);
                            myViewHolderList.get(id).item_rightnow_default.setVisibility(View.GONE);
                            myViewHolderList.get(id).item_lastperiod_ll.setVisibility(View.VISIBLE);
                            myViewHolderList.get(id).item_lastperiod_person.setText("ID: "+data.getList().get(0).getUsername());
                            myViewHolderList.get(id).item_rightnow_price.setText("当前价: ￥" + data.getList().get(0).getPrice());
                            myViewHolderList.get(id).rightnow_openteam.setText("你已最高");
                            myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
                            myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                        }
                    }
                }
            }
        }
        //更新上期商品活动是否失效
        public void notifyLastPeriod() {
            if(temporaryf1_listdata!=null) {
                for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
                    String id = temporaryf1_listdata.get(i).getId();
                    if(auctionResultData.getId().equals(id)) {
                        if (myViewHolderList.containsKey(id)) {
                            myViewHolderList.get(id).item_rightnow_price.setText("当前价: ￥0");
                            myViewHolderList.get(id).rightnow_openteam.setText(R.string.app_fragment3_keyname);
                            myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
                            myViewHolderList.get(id).rightnow_openteam.setEnabled(true);
                            if (lastperiodBean.get(id).ispass_in()) {
                                myViewHolderList.get(id).item_rightnow_default.setVisibility(View.GONE);
                                myViewHolderList.get(id).item_lastperiod_failed.setVisibility(View.VISIBLE);
                                myViewHolderList.get(id).item_lastperiod_ll.setVisibility(View.GONE);
                            } else {
                                myViewHolderList.get(id).item_lastperiod_failed.setVisibility(View.GONE);
                                myViewHolderList.get(id).item_rightnow_default.setVisibility(View.GONE);
                                myViewHolderList.get(id).item_lastperiod_ll.setVisibility(View.VISIBLE);
                                String lastDes = getString(R.string.app_last_winner);
                                myViewHolderList.get(id).item_lastperiod_person.setText(lastDes + lastperiodBean.get(id).getUsername());
                            }
                        }
                    }
                }
            }
        }
        //更新全部商品时间
        public void notifyTimeData(){

            if( temporaryf1_listdata!=null) {

                /**
                 * 如果是我在买的界面，移除倒计时归零的的商品
                 */
                if (auction_style.equals("mine_auctioning")) {
                    for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
                        AuctionActivityData.ListBean listBean = temporaryf1_listdata.get(i);
                        int time =  listBean.getTime();
                        int start =  listBean.getStart();
                        String id = listBean.getId();
                        if (myViewHolderList.containsKey(id)) {
                            boolean isstart = isStartMap.get(id);
                            boolean isMost =  isMostMap.get(id);
                            //有start时间时
                            if(isstart) {
                                myViewHolderList.get(id).rightnow_openteam.setText("即将开始");
                                myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                                myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_yellow_bg2);
                                setCountDown(myViewHolderList.get(id), start);
                                if(start==0)
                                {
                                    myViewHolderList.get(id).rightnow_openteam.setText(R.string.app_fragment3_keyname);
                                    myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
                                    myViewHolderList.get(id).item_rightnow_default.setVisibility(View.VISIBLE);
                                    myViewHolderList.get(id).item_lastperiod_failed.setVisibility(View.GONE);
                                    myViewHolderList.get(id).item_lastperiod_ll.setVisibility(View.GONE);
                                    myViewHolderList.get(id).rightnow_openteam.setEnabled(true);
                                    isStartMap.put(id,false);
                                }
                            }
                            //没有start时间时
                            else {
                                setCountDown(myViewHolderList.get(id), time);
                                if(time>0) {
                                    if (!isMost) {
                                        myViewHolderList.get(id).rightnow_openteam.setText(R.string.app_fragment3_keyname);
                                        myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
                                        myViewHolderList.get(id).rightnow_openteam.setEnabled(true);

                                    } else {
                                        myViewHolderList.get(id).rightnow_openteam.setText("你已最高");
                                        myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
                                        myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                                    }
                                }
                                if (time == 0) {
                                    myViewHolderList.get(id).kill_millsecond.setText("00");
                                    myViewHolderList.get(id).kill_minute.setText("00");
                                    myViewHolderList.get(id).kill_second.setText("00");
                                    myViewHolderList.get(id).rightnow_openteam.setText("出价结束");
                                    myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
                                    myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                                    isMostMap.put(id,false);
//                                    myViewHolderList.remove( temporaryf1_listdata.get(i).getId());
//                                    temporaryf1_listdata.remove(i);
//                                    adapter.notifyDataSetChanged();
                                }

                            }

                        }
                    }
                } else {
                    for (int i = 0; i <  temporaryf1_listdata.size(); i++) {
                        AuctionActivityData.ListBean listBean = temporaryf1_listdata.get(i);
                        int time =  listBean.getTime();
                        int start =  listBean.getStart();


                        String id = listBean.getId();
                        if (myViewHolderList.containsKey(id)) {
                            boolean isstart = isStartMap.get(id);
                            boolean isMost =  isMostMap.get(id);
                            //有start时间时
                            if(isstart) {
                                myViewHolderList.get(id).rightnow_openteam.setText("即将开始");
                                myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                                myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_yellow_bg2);
                                setCountDown(myViewHolderList.get(id), start);
                                if(start==0)
                                {
                                    myViewHolderList.get(id).rightnow_openteam.setText(R.string.app_fragment3_keyname);
                                    myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
                                    myViewHolderList.get(id).item_rightnow_default.setVisibility(View.VISIBLE);
                                    myViewHolderList.get(id).item_lastperiod_failed.setVisibility(View.GONE);
                                    myViewHolderList.get(id).item_lastperiod_ll.setVisibility(View.GONE);
                                    myViewHolderList.get(id).rightnow_openteam.setEnabled(true);
                                    isStartMap.put(id,false);
                                }
                            }
                            //没有start时间时
                            else {

                                setCountDown(myViewHolderList.get(id), time);
                                if(time>0) {
                                    if (!isMost) {
                                        myViewHolderList.get(id).rightnow_openteam.setText(R.string.app_fragment3_keyname);
                                        myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_red_bg2);
                                        myViewHolderList.get(id).rightnow_openteam.setEnabled(true);

                                    } else {
                                        myViewHolderList.get(id).rightnow_openteam.setText("你已最高");
                                        myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
                                        myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                                    }
                                }
                                if (time == 0) {
                                    myViewHolderList.get(id).kill_millsecond.setText("00");
                                    myViewHolderList.get(id).kill_minute.setText("00");
                                    myViewHolderList.get(id).kill_second.setText("00");
                                    myViewHolderList.get(id).rightnow_openteam.setText("出价结束");
                                    myViewHolderList.get(id).rightnow_openteam.setBackgroundResource(R.drawable.corner_gray_bg2);
                                    myViewHolderList.get(id).rightnow_openteam.setEnabled(false);
                                    isMostMap.put(id,false);
                                }
                            }
                        }
                    }
                }
            }
        }

    }

    private void setCountDown(ViewHolder holder, int time) {
        int day = 60 * 60 * 24;
        int hour = 60 * 60;
        int min = 60;
        double d1 = time * 1.0 / day;
        if(time < 0){
            time = 0;
        }
        if(d1 > 1){
            holder.ll_count_down1.setVisibility(View.GONE);
            holder.ll_count_down2.setVisibility(View.VISIBLE);
            int dayNum = time / day;
            int hourNum = time /hour % 24;
            int minuteNum = time /min % 60;
            holder.cd_day.setText(dayNum+"天");
            holder.cd_hour.setText(hourNum+"时");
            holder.cd_minute.setText(minuteNum+"分");
        }else {
            holder.ll_count_down1.setVisibility(View.VISIBLE);
            holder.ll_count_down2.setVisibility(View.GONE);
            String hour1 = String.format("%02d", time / 3600);
            String minute1 = String.format("%02d", time % 3600 / 60);
            String second1 = String.format("%02d", time % 60);
            holder.kill_minute.setText(hour1);
            holder.kill_second.setText(minute1);
            holder.kill_millsecond.setText(second1);
        }
//        String minute1 = String.format("%02d", time1/ 3600);
//        String second1 = String.format("%02d", time1  % 3600 / 60);
//        String millsecond1 = String.format("%02d", time1% 60);
//        holder.kill_millsecond.setText(millsecond1);
//        holder.kill_minute.setText( minute1);
//        holder.kill_second.setText(second1);
    }

    static class ViewHolder {
        int time_position;
        TextView kill_minute ;
        TextView kill_second ;
        TextView kill_millsecond ;
        TextView item_rightnow_price;
        TextView rightnow_openteam;
        TextView item_rightnow_default;
        LinearLayout item_lastperiod_failed,item_lastperiod_ll,item_rightnow_ll,ll_count_down1,ll_count_down2;
        TextView item_lastperiod_person;
        ImageView item_grid_aishang_img;
        TextView item_grid_detail_like_title;
        TextView cd_day,cd_hour,cd_minute;
    }



    @Override
    public void onDestroyView()
    {
        super.onDestroyView();
        //view = null;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        isRunning=false;
        service = null;
        handler1.removeCallbacks(mRunnable);
        handler2.removeCallbacks(mRunnable4);
        getActivity().unregisterReceiver(mBroadcastReceiver);
        listdata.clear();
        myViewHolderList.clear();
        temporaryf1_listdata.clear();
        mBroadcastReceiver  = null;
    }

}




